import { View } from "../../../mvc/core/View";
import { SpecialShortcutsItem } from "../../net/command/bossField/SpecialShortcutsItem";
import { CDItemData } from "../../cache/CDItem/CDItemData";
import { LayerManager } from "../../manager/LayerManager";
import { TweenMax } from "../../../../com/greensock/TweenMax";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { Language } from "../../../../extend/language/Language";
import { SceneRange } from "../../scene/map/SceneRange";
import { Global } from "../../../../com/gengine/global/Global";
import { SkillInfo } from "../../model/SkillInfo";
import { Cache } from "../../cache/Cache";
import { ClockManager } from "../../manager/ClockManager";
import { SkillConst } from "../skill/SkillConst";
import { SkillRules } from "../../rules/SkillRules";
import { ESkillType } from "../../../../Message/Public/ESkillType";
import { DataEvent } from "../../events/DataEvent";
import { GameController } from "../../mvc/GameController";
import { ObjCreate } from "../common/ObjCreate";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { CrossDefenceCopyMenuBase } from "../copy/crossDefenceCopy/CrossDefenceCopyMenuBase";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class SpecialSkillPanel
    
    export  class SpecialSkillPanel extends View
    {
        constructor(arg1: int=5)
        {
            super();
            this._skillVec = new Vector.<SpecialShortcutsItem>();
            this._moveRec = new Object /* flash.geom.Rectangle */();
            this._cd = new CDItemData();
            this._skillMaxNum = arg1;
            this.layer = LayerManager.uiLayer;
            this.createChildren();
            this.layout();
            return;
        }

        protected clickHideHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._tweening) 
            {
                return;
            }
            if (this._btnHide.scaleX != -0.8) 
            {
                this._btnHide.scaleX = -0.8;
                this.showBody();
            }
            else 
            {
                this._btnHide.scaleX = 0.8;
                this.hideBody();
            }
            this._btnHide.scaleY = 0.9;
            return;
        }

        protected hideBody(): void
        {
            this._tweening = true;
            TweenMax.to(this._container, 0.25, {"scaleY": 0, "onComplete": this.hideShowOpComplete});
            TweenMax.to(this._crossTowerCell.bg, 0.25, {"height": 20});
            return;
        }

        protected showBody(): void
        {
            this._tweening = true;
            TweenMax.to(this._container, 0.25, {"scaleY": 1, "onComplete": this.hideShowOpComplete});
            TweenMax.to(this._crossTowerCell.bg, 0.25, {"height": 71});
            return;
        }

        protected hideShowOpComplete(): void
        {
            this._tweening = false;
            ToolTipsManager.unregister(this._btnHide);
            var loc1=Language.getString(80359);
            if (this._btnHide.scaleX == -1) 
            {
                loc1 = Language.getString(80360);
            }
            ToolTipsManager.register(this._btnHide, null, loc1);
            return;
        }

        public SpecialSkillPanel.get showMode(): int
        {
            return this._showMode;
        }

        protected onMoveBtnMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._moveRec.x = 0;
            this._moveRec.y = 0;
            this._moveRec.width = SceneRange.display.width - 30;
            this._moveRec.height = SceneRange.display.height - 30;
            startDrag(false, this._moveRec);
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        protected onStageMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            stopDrag();
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        public setSkillListData(arg1: Array<any>): void
        {
            var loc1=null;
            var loc3=null;
            var loc4=NaN;
            var loc2=0;
            while (loc2 < this._skillMaxNum) 
            {
                if (loc2 < arg1.length) 
                {
                    loc1 = arg1[loc2] as SkillInfo;
                    this._skillVec[loc2].dragSource = loc1;
                    this._skillVec[loc2].setAmountText(-1);
                    if (loc4 > 0) 
                    {
                        if (!(loc3 = Cache.instance.timeCdCache.getSkillCd(loc1))) 
                        {
                            loc3 = Cache.instance.timeCdCache.addSkillCd(loc1);
                        }
                        loc4 = loc1.cdDt.time - ClockManager.instance.nowDate.time;
                        loc3.totalTime = loc4;
                        this._skillVec[loc2].doCoolDown(loc3, true);
                    }
                }
                else 
                {
                    this._skillVec[loc2].dragSource = null;
                }
                ++loc2;
            }
            return;
        }

        public keyActive(arg1: int): void
        {
            if (arg1 >= 0 && arg1 < this._skillVec.length) 
            {
                this._skillVec[arg1].doAction();
            }
            return;
        }

        public useSkillItem(arg1: SkillInfo, arg2: Boolean=true, arg3: Boolean=true): void
        {
            var loc1=null;
            var loc2=null;
            var loc4=null;
            if (!arg1) 
            {
                return;
            }
            var loc3=-1;
            var loc5=0;
            while (loc5 < this._skillVec.length) 
            {
                if (loc1 = (loc2 = this._skillVec[loc5] as SpecialShortcutsItem).dragSource as SkillInfo) 
                {
                    if (!SkillConst.isNoCoolDownBySKill(loc1.tSkill)) 
                    {
                        if (!(loc4 = Cache.instance.timeCdCache.getSkillCd(loc1))) 
                        {
                            loc4 = Cache.instance.timeCdCache.addSkillCd(loc1);
                        }
                        if (loc1 != arg1) 
                        {
                            if (arg3) 
                            {
                                if (!SkillRules.isMarrySkill(loc1.tSkill)) 
                                {
                                    if (loc4) 
                                    {
                                        if (arg1.skillType == ESkillType._ESkillTypeSwitchBuff && loc1.skillType == ESkillType._ESkillTypeSwitchBuff && arg2) 
                                        {
                                            loc4.resetTotalTime();
                                            loc2.doCoolDown(loc4, true);
                                        }
                                        else if (loc4.isCoolDown != false) 
                                        {
                                            if (loc4.isLessCd()) 
                                            {
                                                loc4.reset();
                                                loc4.totalTime = 1000;
                                                loc2.doCoolDown(loc4, true);
                                            }
                                        }
                                        else 
                                        {
                                            loc4.totalTime = 1000;
                                            loc2.doCoolDown(loc4, true);
                                        }
                                    }
                                }
                            }
                        }
                        else 
                        {
                            if (arg2) 
                            {
                                loc4.resetTotalTime();
                                loc2.doCoolDown(loc4, true);
                            }
                            else if (arg3) 
                            {
                                loc4.totalTime = 1000;
                                loc2.doCoolDown(loc4, true);
                            }
                            loc3 = loc5;
                        }
                    }
                }
                ++loc5;
            }
            if (loc3 < 0) 
            {
                loc1 = Cache.instance.skill.getSkillInfoById(arg1.skillId);
                if (loc4 = Cache.instance.timeCdCache.getSkillCd(loc1)) 
                {
                    if (arg2) 
                    {
                        loc4.resetTotalTime();
                        loc4.startCoolDown();
                    }
                    else if (arg3) 
                    {
                        loc4.totalTime = 1000;
                        loc4.startCoolDown();
                    }
                }
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.setSkillListData([]);
            return;
        }

        public getSkillNum(): int
        {
            return this._skillMaxNum;
        }

        protected onStageResize(arg1: DataEvent): void
        {
            this.layout();
            return;
        }

        protected layout(): void
        {
            var loc1=null;
            if (this._showMode == SpecialSkillPanel.ShowMode_Normal) 
            {
                loc1 = GameController.gameui.getGameui();
                this.x = loc1.nvPosX + 160;
                this.y = loc1.nvPosY - 65;
            }
            return;
        }

        protected createChildren(): void
        {
            var loc1=null;
            this._container = new Object /* flash.display.Sprite */();
            this._container.x = 18;
            this.addChild(this._container);
            var loc2=0;
            while (loc2 < this._skillMaxNum) 
            {
                loc1 = new SpecialShortcutsItem(loc2);
                loc1.x = loc2 * this.SkillSlotWidth;
                loc1.y = 0;
                loc1.IndexLabelTxt(loc2 + 1);
                loc1.isDragAble = false;
                loc1.isDropAble = false;
                loc1.isThrowAble = false;
                this._container.addChild(loc1);
                this._skillVec.push(loc1);
                ++loc2;
            }
            this._moveBtn = ObjCreate.createGButton("", 223, 18, 24, 22, this, "MoveBtn2");
            this._moveBtn.x = 223 + (this._skillMaxNum - this.skillDefaultNum) * this.SkillSlotWidth;
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(60053), "#FFFFFF");
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            LoaderManager.instance.load("DefendCopyPropBg.png", this.onPropListBgLoaded);
            return;
        }

        public static get instance(): SpecialSkillPanel
        {
            if (!SpecialSkillPanel._instance) 
            {
                SpecialSkillPanel._instance = new SpecialSkillPanel();
            }
            return SpecialSkillPanel._instance;
        }

        protected onPropListBgLoaded(arg1: ImageInfo): void
        {
            this._bg = new ScaleBitmap(arg1.bitmapData.clone());
            this._bg.scale9Grid = new Object /* flash.geom.Rectangle */(25, 0, 190, 54);
            this._bg.width = this.SkillBgNoSkillWidth + this._skillMaxNum * this.SkillSlotWidth;
            this._bg.height = 54;
            this.addChildAt(this._bg, 0);
            this.showMode = this._showMode;
            return;
        }

        public set showMode(arg1: int)
        {
            this._showMode = arg1;
            if (this._bg == null) 
            {
                return;
            }
            if (arg1 != SpecialSkillPanel.ShowMode_Normal) 
            {
                if (arg1 == SpecialSkillPanel.ShowMode_CrossTower) 
                {
                    DisplayUtil.removeMe(this._bg);
                    this.initCrossTowerMode();
                }
            }
            else 
            {
                this.addChildAt(this._bg, 0);
                DisplayUtil.removeMe(this._crossTowerCell);
                this._crossTowerCell = null;
                this._moveBtn.x = 223 + (this._skillMaxNum - this.skillDefaultNum) * this.SkillSlotWidth;
                this._moveBtn.y = 0;
                DisplayUtil.removeMe(this._btnHide);
            }
            return;
        }

        public static hasInstance(): Boolean
        {
            return !(SpecialSkillPanel._instance == null);
        }

        /* internal  */initCrossTowerMode(): void
        {
            var loc1=null;
            var loc2=0;
            if (this._crossTowerCell == null) 
            {
                loc1 = [];
                loc2 = 0;
                while (loc2 < this._skillMaxNum) 
                {
                    loc1.push(loc2);
                    ++loc2;
                }
                this._crossTowerCell = new CrossDefenceCopyMenuBase(loc1, "CrossTowerSkillTitle.png", "CrossTowerSkillIcon.png", null);
                this._crossTowerCell.setNoMove();
            }
            this._crossTowerCell.y = -27;
            this._crossTowerCell.x = 8;
            this._moveBtn.x = this._crossTowerCell.width - 25 + 8;
            this._moveBtn.y = this._crossTowerCell.y + 1;
            this.addChildAt(this._crossTowerCell, 0);
            if (!this._btnHide) 
            {
                this._btnHide = GlobalClass.getInstance("showBtn");
            }
            this._btnHide.x = this._moveBtn.x - 23 + 10;
            this._btnHide.y = this._moveBtn.y + 10;
            this._btnHide.rotationZ = 90;
            this._btnHide.scaleX = -0.8;
            this._btnHide.scaleY = 0.9;
            this.addChild(this._btnHide);
            this._btnHide.addEventListener(flash.events.MouseEvent.CLICK, this.clickHideHandler);
            this.hideShowOpComplete();
            return;
        }

        protected /* const */SkillBgNoSkillWidth: int=49;

        protected /* const */SkillSlotWidth: int=41;

        protected /* const */skillDefaultNum: int=5;

        public static /* const */ShowMode_CrossTower: int=1;

        public static /* const */ShowMode_Normal: int=2;

        protected /* var */_skillMaxNum: int=5;

        protected /* var */_skillVec: Vector.<SpecialShortcutsItem>;

        protected /* var */_moveRec: Object /* flash.geom.Rectangle */;

        protected /* var */_moveBtn: GButton;

        protected /* var */_container: Object /* flash.display.Sprite */;

        protected /* var */_cd: CDItemData;

        /* internal */ /* var */_showMode: int=2;

        protected /* var */_crossTowerCell: CrossDefenceCopyMenuBase;

        protected /* var */_bg: ScaleBitmap;

        /* internal */ static /* var */_instance: SpecialSkillPanel;

        /* internal */ /* var */_tweening: Boolean=false;

        /* internal */ /* var */_btnHide: Object /* flash.display.DisplayObject */;
    }
